using System;

namespace CodeStory.WebControls
{
	public interface ITreeGridDataObject
	{
		string ParentPath { get;}
		string Path { get; set; }
		object DataObjectID { get; set; }
		object DataObject { get;set;}
		ITreeGridDataObject[] GetChildren();

		ITreeGridDataObject GetParent(string id);
	}
	public class TreeGridDataObject : ITreeGridDataObject
	{
		private string parentPath = "";
		private string path;
		private object dataObjectID;
		private object dataObject;

		IHierarchyDataSelector selector;

		public TreeGridDataObject(object dataObject,object dataObjectID,string parentPath,IHierarchyDataSelector selector) {
			this.dataObject = dataObject;
			this.dataObjectID = dataObjectID;
			this.parentPath = parentPath;
			this.selector = selector;
		}

		public string ParentPath {
			get { return parentPath; }
		}
		public string Path {
			get {
				if (string.IsNullOrEmpty(path)) {
					path = string.Format("{0}/{1}",parentPath,dataObjectID);
				}
				return path; 
			}
			set { path = value; }
		}
		public object DataObjectID {
			get { return dataObjectID; }
			set { dataObjectID = value; }
		}
		public object DataObject {
			get { return dataObject; }
			set { dataObject = value; }
		}

		public ITreeGridDataObject[] GetChildren() {
			return selector.SelectData(Path);
		}

		public ITreeGridDataObject GetParent(string _parentPath) {
			return selector.GetData(_parentPath);
		}
	}
}